package com.yzt.zhuju.dialog;

import android.content.DialogInterface;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.yzt.zhuju.R;
import com.yzt.zhuju.utils.PermissionUtils;

/**
 * author : bob
 * date   : 2022/12/2
 * desc   : 权限通知弹窗
 */
public class NotifyPermissionsDialog extends CenterBaseDialog {

    private OnCloseListener listener;

    private boolean isGoToOpen = false;

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_fragment_notify_permissions;
    }

    @Override
    public void bindView(View v) {

        v.findViewById(R.id.iv_close).setOnClickListener(v12 -> dismiss());

        TextView tvContent = v.findViewById(R.id.tv_content);
        tvContent.setText(getString(R.string.open_notify_miss));

        v.findViewById(R.id.btn_submit).setOnClickListener(v1 -> {
            isGoToOpen = true;
            PermissionUtils.openNotificationPermissionSetting(getContext());
            dismiss();
        });
    }

    public void setListener(OnCloseListener listener) {
        this.listener = listener;
    }

    public interface OnCloseListener {

        void onClose(boolean isGoToOpen);
    }

    @Override
    public void onDismiss(@NonNull DialogInterface dialog) {
        super.onDismiss(dialog);
        if (listener != null) {
            listener.onClose(isGoToOpen);
        }
    }
}

